package com.cooper.service.admin;

import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooper.dao.admin.DisplayPicConfigDAO;
import com.cooper.entity.DisplayPicConfigListDo;
import com.cooper.entity.DisplaySelectConfigListDo;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.vo.DisplayPicConfigVo;

@Service
public class DisplayPicConfigService {

	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	DisplayPicConfigDAO displayPicConfigDAO;
	
	public void addDisplayPicConfig(DisplayPicConfigListDo displayPicConfigListDo){
		try {
			displayPicConfigDAO.addDisplayPicConfig(displayPicConfigListDo);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-addDisplayPicConfig-error", e);
		}
	}
	
	public void addDisplaySelectConfigListDo(DisplaySelectConfigListDo displaySelectConfigListDo){
		try {
			displayPicConfigDAO.addDisplaySelectConfig(displaySelectConfigListDo);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-addDisplaySelectConfigListDo-error", e);
		}
	}
	
	public void removeDisplaySelectConfigListDo(Long id){
		try {
			displayPicConfigDAO.deleteSelectConfig(id);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-updateDisplayPicConfig-error", e);
		}
	}
	
	public void updateDisplayPicConfig(DisplayPicConfigListDo displayPicConfigListDo){
		try {
			displayPicConfigDAO.updateDisplayPicConfig(displayPicConfigListDo);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-updateDisplayPicConfig-error", e);
		}
	}
	
	public DisplayPicConfigListDo findDisplayPicConfigById(Long id){
		try {
			return displayPicConfigDAO.getDisplayPicConfig(id);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-addDisplayPicConfig-error", e);
		}
		return null;
	}
	
	public DisplaySelectConfigListDo findDisplaySelectConfig(Long outerId,String selectType){
		try {
			return displayPicConfigDAO.getDisplaySelectConfigList(outerId, selectType);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-findDisplaySelectConfig-error", e);
		}
		return null;
	}
	
	public void remove(Long id){
		try {
			displayPicConfigDAO.delete(id);
		} catch (Exception e) {
			logger.error("DisplayPicConfigService-addDisplayPicConfig-error", e);
		}
	}
		
	@SuppressWarnings("unchecked")
	public PageResult<DisplayPicConfigVo> queryDisplayPicConfigPage(DisplayPicConfigVo queryParamVo, PageInfo pageInfo){
		int rowCount = this.displayPicConfigDAO.queryDisplayPicConfigCount(queryParamVo);
		pageInfo.setRowCount(rowCount);
		if(0 == rowCount){
			return new PageResult<DisplayPicConfigVo>(Collections.EMPTY_LIST, pageInfo);
		}
		List<DisplayPicConfigVo> dataList = this.displayPicConfigDAO.queryDisplayPicConfigs(queryParamVo, pageInfo);
		return new PageResult<DisplayPicConfigVo>(dataList, pageInfo);
	}
	
	
}
